<?php
/*
	[BuyPg] (C) 2010-2011 Buypg
	$Id: CommentAction.class.php 2011-5-5 14:26:45 wufujun $
 */

if (!defined('THINK_PATH')) {
	exit('Access Denied');
}

class CommentAction extends BpAction{
	
	public function commentlist() {
		global $_SGLOBAL;
		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : 0;
		$DbSite = M("NbSite");
		$arrSite = $DbSite->where("site_id = $siteid and flag = 1")->find();
		if($arrSite){
			$DbComment = M("NbCommend");
			$arrComment = $DbComment->where("site_id = $siteid")->order("commend_dt DESC")->select();
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
		
		//定义左侧分类
		$LeftCate = getLeftCategory();
		
		//模板输出
		$this->assign('leftcate' , $LeftCate);
		$this->assign('arrsite' , $arrSite);
		$this->assign('arrcomment' , $arrComment);
		$this->display();
	}
	
	public function insert(){
		global $_SGLOBAL;
		$siteid = $_POST['siteid'];
		$jumpUrl =  U(APP_NAME."://Webping/website" , array('siteid' => $siteid));
		$this->assign('jumpUrl' , $jumpUrl);
		//判断用户
		if(($mserr = checkstatus('user'))){
			if($mserr['flag'] == 1){
				checkrefer($_SERVER['REQUEST_METHOD'], $jumpUrl);
				$this->assign('jumpUrl' , __APP__."/User/login");
			}
			$this->error($mserr['msg']);
		}
		import("@.ORG.Input");
		$data = array(
			'siteid' => $siteid,
			'content' => Input::nl2Br(Input::deleteHtmlTags($_POST['content'])),
			'commend_date' => date("Y-m-d H:i:s", $_SGLOBAL['timestamp']),
			'commend_dt' => $_SGLOBAL['timestamp'],
			'user_id' => $_SGLOBAL['G_uid'],
			'__hash__' => $_POST['__hash__'],
		);
		$DbComment = D("NbCommend");
		if($DbComment->create($data)){
			if($DbComment->add() !== FALSE){
				$this->success("您已经成功发表评论！");
			}else{
				$this->error("评论发表失败！");
			}
		}else{
			$this->error($DbComment->getError());
		}
		
	}
}

?>
